#include <iostream>
#include <cstdio>
#include <ctime>
#include <cstdlib>

int main()
{
	srand(time(0));
	int t = 50;
	std::cout << t << '\n';
	for (int i = 0; i < t; i++) {
		int n = rand() % 500;
		std::cout << n << ' ' << n << '\n';
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				std::cout << rand() % 2;
			}
			std::cout << '\n';
		}
		for (int i = 1; i <= n; i++) {
			std::cout << i << '\n';
		}
	}
}

